﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;

public partial class Admin_Gopy : System.Web.UI.Page
{
    DataProvider duLieu = new DataProvider();
    ListBox listBox = new ListBox();
    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!IsPostBack)
        {
            Load_Danh_Muc();
        }
    }

    public void Load_Danh_Muc()
    {
        DataTable bangchude = null;
        bangchude = duLieu.Load_Du_Lieu_Admin_New("select * from lhgopy order by magopy DESC", listBox);
        if (bangchude.Rows.Count != 0)
        {
            gvDuLieu.DataSource = bangchude;
            gvDuLieu.DataBind();
        }
        else
        {
            thongbaotrantrung.Text = "<font color='red'>Hiện Tại Trang Web Chưa Có Góp ý Nào.</font>";
        }
    }

    protected void gvDuLieu_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvDuLieu.PageIndex = e.NewPageIndex;
        Load_Danh_Muc();
    }



    protected void gvDuLieu_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
    {
        listBox.Items.Clear();
        duLieu.MakeDuLieu(listBox, gvDuLieu.Rows[e.RowIndex].Cells[0].Text);
        if (duLieu.Luu_Du_Lieu_Admin_New("delete from lhgopy where magopy=?", listBox) == 0)
        {
            thongbaotrantrung.Text = "<font color='red'>Xóa Không Thành Công.</font><hr/>";
            return;
        }
        Response.Redirect("Gopy.aspx");
    }

    protected void gvDuLieu_Sorting(object sender, System.Web.UI.WebControls.GridViewSortEventArgs e)
    {
        string LenhSql = "select * from lhgopy";

        if (!string.IsNullOrEmpty(e.SortExpression))
        {
            LenhSql = LenhSql + " Order by " + e.SortExpression;
        }
        gvDuLieu.DataSource = duLieu.Load_Du_Lieu_Admin_New(LenhSql, listBox);
        gvDuLieu.DataBind();
    }
}